package com.bjpowernode.springboot.web;

import com.bjpowernode.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    @RequestMapping(value = "/login")
    public @ResponseBody String login(HttpServletRequest request){
        User user = new User();
        user.setId(1001);
        user.setName("zhangsan");
        request.getSession().setAttribute("user",user);
        return "login success";
    }

    @RequestMapping(value = "/center")
    public @ResponseBody String center(){
        return "center message";
    }

    @RequestMapping(value = "/out")
    public @ResponseBody String out(){
        return "out message";
    }

    @RequestMapping(value = "/error")
    public @ResponseBody String error(){
        return "error";
    }

    @RequestMapping(value = "/logout")
    public @ResponseBody String logout(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return "logout success";
    }
}
